﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using AutoMapper;

namespace OnlineBookstore.HelpClass
{
	public static class Map
	{
        /// <summary>
        /// 映射
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="V"></typeparam>
        /// <param name="source"></param>
        /// <returns></returns>
        public static T MapTo<T, V>(this V source)
                 where T : class
                 where V : class
        {
            if (source == null) return default(T);
            var config = new MapperConfiguration(cfg => cfg.CreateMap<V, T>());
            var mapper = config.CreateMapper();
            return mapper.Map<T>(source);
        }

    }
}